

import cv2
from PIL import Image
import os

for file in os.listdir('/home/unionsys/Pictures/color/val/'):
    print(file)
    color_img = cv2.imread('/home/unionsys/Pictures/color/val/'+file)
    gray_img=cv2.cvtColor(color_img,cv2.COLOR_RGB2GRAY)
    gray=Image.fromarray(gray_img)
    gray.save('/home/unionsys/Pictures/gray/val/'+file)

